﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Db4objects.Db4o;
using Db4objects.Db4o.Query;
using Db4objects.Db4o.Linq;

namespace Yosca
{
    public class Invoice
    {
		private DateTime _estimateDate;
		private DateTime _scheduledDate;
		private DateTime _completionDate;
		private String _jAddress;
		private String _jCity;
		private String _jState;
		private String _jZip;
		private String _notes;
        private int _invoiceStatus;
        private string _invoiceStat;

        public bool[] flags { set; get; }
        public int invoiceStatus
        {
            get { return _invoiceStatus; }
            set { _invoiceStatus = value; }
        }
        public String invoiceStat
        {
            get { return getInvoiceStatus(); }
            set { _invoiceStat = value; }
        }

        public string getInvoiceStatus()
        {
            string s;
            switch (this.invoiceStatus)
            {
                case 1:
                    s = "Estimate";
                    break;
                case 2:
                    s = "Job Scheduled";
                    break;
                case 3:
                    s = "Payment Due";
                    break;
                case 4:
                    s = "Payment";
                    break;
                case 5:
                    s = "Paid in Full";
                    break;
                default:
                    s = "Not Started";
                    break;

            }
            return s;
        }
		public DateTime estimateDate
		{
			get { return _estimateDate; }
			set { _estimateDate = value; }
		}
		public DateTime scheduledDate
		{
			get { return _scheduledDate; }
			set { _scheduledDate = value; }
		}
		public DateTime completionDate
		{
			get { return _completionDate; }
			set { _completionDate = value; }
		}
				public string jAddress
		{
			get { return _jAddress; }
			set { _jAddress = value; }
		}
		public string jCity
		{
			get { return _jCity; }
			set { _jCity = value; }
		}
		public string jState
		{
			get { return _jState; }
			set { _jState = value; }
		}
		public string jZip
		{
			get { return _jZip; }
			set { _jZip = value; }
		}
		public string notes
		{
			get { return _notes; }
			set { _notes = value; }
		}
		
        public long inv_num { set; get; }
        public Customer defCust { set; get; }
        public IList<Worker> workerList { set; get; }
		
		

        public Invoice()
        {
            defCust = new Customer();
            workerList = null;
			_jAddress = "";
			_jCity = "";
			_jState = "";
			_jZip = "";
			_notes = "";
            flags = new bool[5] { false, false, false, false, false };
            //START AUTO INCREMENT CODE
            IObjectContainer inv_num_db = Db4oFactory.OpenFile("Inv_Num.db4o");
            Invoice_Number numObject;
            IList<Invoice_Number> result = inv_num_db.Query<Invoice_Number>(typeof(Invoice_Number));
           
            if (result.Count > 0)
            {
                numObject = result.First<Invoice_Number>();
            }
            else numObject = new Invoice_Number();

            if (numObject.number == -1)//no value in db? Start from 1
            {
                numObject.number = 1;
                inv_num = numObject.number;
                inv_num_db.Store(numObject);
            }
            else
            {
                numObject.number++;
                inv_num = numObject.number;
                inv_num_db.Store(numObject);
            }
            inv_num_db.Close();
            //END AUTO INCREMENT CODE
        }
    }

}
